﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using proRFID_DiemDanh.Chung;
using System.Data;
using System.Data.SqlClient;

namespace proRFID_DiemDanh.Users
{
    public class mdUsers
    {
        public static DataTable User_DangKy(string username, string password)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_User_DangKy", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@username", username);
            cmd.Parameters.AddWithValue("@password", password);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }

        public static DataTable User_checkpass(string username,string password)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_User_checkpass", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@username", username);
            cmd.Parameters.AddWithValue("@password", password);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
      
        public static DataTable User_insert(string username, int systemright,bool state)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_User_insert", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@username", username);
            cmd.Parameters.AddWithValue("@systemright", systemright);
            cmd.Parameters.AddWithValue("@state", state);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }
        public static DataTable User_Changepass(string username, string oldpass, string newpass)
        {
            mdMain.OpenConnection();
            SqlCommand cmd = new SqlCommand("sp_User_Changepass", mdMain.cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@username", username);
            cmd.Parameters.AddWithValue("@oldpass", oldpass);
            cmd.Parameters.AddWithValue("@newpass", newpass);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            mdMain.CloseConnection();
            return dt;
        }

       
    }
}